package com.feilong.cn.mybatis.autoV2.proxy;



import com.feilong.cn.mybatis.autoV2.session.AutoSqlSession;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by yangxulong on 2018/4/2.
 */
public class MapperProxy implements InvocationHandler {

    private AutoSqlSession session;

    public MapperProxy(AutoSqlSession session) {
        this.session = session;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        String strId = method.getDeclaringClass().getName() + '.' + method.getName();
        if (session.getConfiguration().getMappedStatement(strId) != null) {
            return session.SelectOne(strId,args[0]);
        } else if (Object.class.equals(method.getDeclaringClass())) {
            return method.invoke(this, args);
        } else {
            return null;
        }

    }
}
